package com.mgkj.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.mgkj.dto.NeedArrivalInsDto;
import com.mgkj.entity.PURMA;
import com.mgkj.entity.Purtg;
import com.mgkj.entity.Purth;
import com.mgkj.entity.Qmsta;
import com.mgkj.entity.yf.Invta;
import com.mgkj.entity.yf.Invtb;
import com.mgkj.vo.NeedArrivalInsVo;
import com.mgkj.vo.SupplierVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author : ssy
 * @date: 2024-02-27
 * @Description:
 */
@Mapper
public interface EnterStorageMapper {


    @DS("demo")
    List<NeedArrivalInsVo> getNeedArrivalIns(NeedArrivalInsDto needArrivalInsDto);

    List<SupplierVo> selecttt();

    @DS("demo")
    String getSL(String workCenter);

    @DS("demo")
    Map<String, Object> selectQMSTA(@Param("workCenter") String workCenter,@Param("dhjydb") String dhjydb,@Param("dhjydh") String dhjydh,@Param("xh") String xh,@Param("jypc") String jypc,@Param("factory") String factory);

    String selectvv(@Param("cd010") String cd010,@Param("cd011") String cd011,@Param("cd012") String cd012);

    Map<String, Object> getNeedInspectByDH(String dhdb, String dhdh, String xh);

    @Select("SELECT MAX(TAC04)+1 FROM QMSTA WHERE TA001 = #{dhdb} AND TA002 = #{dhdh} AND TA003 = #{xh}")
    Integer getJYPC(@Param("dhdb") String dhdb,@Param("dhdh") String dhdh,@Param("xh") String xh);

    @DS("demo")
    Boolean insertQMSTA(Qmsta qmsta);

    @DS("demo")
    Boolean updatePurcd(@Param("updatedAccNumber") Double updatedAccNumber, @Param("accPackageNumber") Double accPackageNumber,
                        @Param("updatedReturnNumber") Double updatedReturnNumber, @Param("returnPackageNumber") Double returnPackageNumber,
                        @Param("updatedScrapNumber") Double updatedScrapNumber, @Param("scrapPackageNumber") Double scrapPackageNumber,
                        @Param("updatedDamageNumber") Double updatedDamageNumber, @Param("breakPackageNumber") Double breakPackageNumber,
                        @Param("dhdb") String dhdb,@Param("dhdh") String dhdh,@Param("xh") String xh);

    @DS("demo")
    @Delete("delete from QMSTA WHERE TA001 = #{ta001} AND TA002 = #{ta002} AND TA003 = #{ta003}")
    void deleteQMSTA(Qmsta qmsta);

    @Select("SELECT MG004 " +
            "FROM CMSMF "  +
            "LEFT JOIN CMSMG ON MF001 = MG001 \n" +
            "WHERE MF001 =  #{ma021} \n" +
            "AND MG002 = (SELECT MAX(MG002) FROM CMSMG) ")
Double selectHL(String ma021);

    @Select("Select COUNT(*)\n" +
            "from  PURTD\n" +
            "Left join PURTC on TC001=TD001 and TC002=TD002\n" +
            "Left join INVMB on TD004=MB001 \n" +
            "LEFT JOIN CMSMQ ON TC001=MQ001\n" +
            "Where TC004= #{supplierNo} \n" +
            "AND TD001 = #{cgdb} AND TD002 = #{cgdh} AND TD003 = #{xh} " +
            "AND TD008+TDC01-TD015-TDC02>0\n" +
            "AND TD016='N' and TD018='Y' \n" +
            "AND MQ003<>'27'")
    Integer isPurchaseOrder(String cgdb, String cgdh, String xh, String supplierNo);

    @Select("SELECT TD001, TD002, TD003, TD004, TD005, TD006, " +
            "TD007, TD008, TD009, TD010, TD011, TD012, TD013, " +
            "TD014, TD015, TD016, TD017, TD018, TD019, TD020, " +
            "TD021, TD022, TD023, TD024, TD025, TD026, TD027, " +
            "TD028, TD029, TD030, TD031, TD032, TD033, TD034, " +
            "TD035, TD036, TD037, TD038, TD039, TD040, TD041, " +
            "TD042, TD043, TD044, TD045, TD046, TD047, TD048, " +
            "TD049, TDC01, TDC02, TDC03, TDC04, TDC05, TDC06, " +
            "TD050, TD051 \n" +
            "from  PURTD\n" +
            "Left join PURTC on TC001=TD001 and TC002=TD002\n" +
            "Left join INVMB on TD004=MB001 \n" +
            "LEFT JOIN CMSMQ ON TC001=MQ001\n" +
            "Where TC004= #{tg005} \n" +
            "AND TC018 = #{sz} " +
            "AND TD001 = #{cgdb} AND TD002 = #{cgdh} AND TD003 = #{xh}\n" +
            "and TD018='Y' \n" +
            "AND MQ003<>'27'")
    Map<String, Object> SelectByPur3(String sz,String cgdb, String cgdh, String xh, String tg005);

    @Select("SELECT TD001, TD002, TD003, TD004, TD005, TD006, " +
            "TD007, TD008, TD009, TD010, TD011, TD012, TD013, " +
            "TD014, TD015, TD016, TD017, TD018, TD019, TD020, " +
            "TD021, TD022, TD023, TD024, TD025, TD026, TD027, " +
            "TD028, TD029, TD030, TD031, TD032, TD033, TD034, " +
            "TD035, TD036, TD037, TD038, TD039, TD040, TD041, " +
            "TD042, TD043, TD044, TD045, TD046, TD047, TD048, " +
            "TD049, TDC01, TDC02, TDC03, TDC04, TDC05, TDC06, " +
            "TD050, TD051 \n" +
            "from  PURTD\n" +
            "Left join PURTC on TC001=TD001 and TC002=TD002\n" +
            "Left join INVMB on TD004=MB001 \n" +
            "LEFT JOIN CMSMQ ON TC001=MQ001\n" +
            "Where TC004= #{tg005} \n" +
            "AND TC018 = #{sz} " +
            "AND TD001 = #{cgdb} AND TD002 = #{cgdh} AND TD003 = #{xh}\n" +
            "AND TD008+TDC01-TD015-TDC02>0\n" +
            "AND TD016='N' and TD018='Y' \n" +
            "AND MQ003<>'27'")
    Map<String, Object> SelectByPur2(String sz,String cgdb, String cgdh, String xh, String tg005);

    @Select("SELECT TD010 FROM PURTD WHERE TD001 = #{TD001} AND TD002 = #{TD002} AND TD003= #{TD003}")
    Double selectOne(String TD001, String TD002, String TD003);

    @Select("SELECT COUNT(TD012) FROM PURTD WHERE " +
            "TD012 < CAST(GETDATE() AS DATE) " +
            "AND TD001 = #{cd010} " +
            "AND TD002 = #{cd011} " +
            "AND TD003 = #{cd012} ")
    Boolean selectCQ(String cd010,String cd011, String cd012);

    @Delete("DELETE FROM PURTG where TG001 = #{tg001} and TG002 = #{tg002} and TG003 = #{tg003}")
    void deletePurtg(Purtg purtg);

    @Delete("DELETE FROM PURTH WHERE TH001 = #{th001} and TH002 = #{th002} and TH003 = #{th003}")
    void deletePurth(Purth purth1);

    @Select("SELECT * FROM PURMA WHERE MA001 = #{workCenter}")
    PURMA selectPURMA(String workCenter);

    Map<String, Object> getOrderInfo(String orderNo);

    @Delete("delete from INVTA WHERE TA001 = #{ta001} AND TA002 = #{ta002}")
    void deleteINVTA(Invta invta);
    @Delete("delete from INVTB WHERE TB001 = #{tb001} AND TB002 = #{tb002} AND TB003 = #{tb003}")
    void deleteINVTB(Invtb invtb);

    List<NeedArrivalInsVo> needArrivalInsCustomer();

}
